<?php

/**
 * This is the model class for table "tbl_bidjob".
 *
 * The followings are the available columns in table 'tbl_bidjob':
 * @property integer $id
 * @property integer $job_id
 * @property integer $user_id
 * @property string $currency
 * @property double $money
 * @property string $timeduration
 * @property string $checkPoint
 * @property string $desc
 * @property string $timepost
 *
 * The followings are the available model relations:
 * @property Job $job
 * @property Users $user
 */
class Bidjob extends CActiveRecord
{
    public function getCurrencyType() {
        return array(1=>'VNĐ', 2=>'USD');
	}
    
	/**
	 * Returns the static model of the specified AR class.
	 * @return Bidjob the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_bidjob';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('currency, money, timeduration, checkPoint, desc', 'required'),
			array('money', 'numerical'),
			array('timeduration, checkPoint', 'length', 'max'=>100),
			array('desc', 'length', 'max'=>128),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'job' => array(self::BELONGS_TO, 'Job', 'job_id'),
			'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'currency' => 'Tiền tệ',
			'money' => 'Tiền đặt (chỉ nhập số)',
			'timeduration' => 'Khoảng thời gian hoàn thành',
			'checkPoint' => 'Mốc kiểm tra',
			'desc' => 'Cam kết về dự án',
		);
	}
    
    /**
     * Prepares timepost and user_id attributes before performing validation.
     */
    protected function beforeValidate() {
        if ($this->isNewRecord) {
            $this->timepost = new CDbExpression('NOW()');
            $this->user_id = Yii::app()->user->id;
        }
        return parent::beforeValidate();
    }
}